package a66weding.com.jiehuntong.activity;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.KeyEvent;
import android.view.View;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.application.GlobalApplication;
import a66weding.com.jiehuntong.beans.ErrorBean;
import a66weding.com.jiehuntong.beans.FragmentModule;
import a66weding.com.jiehuntong.beans.SuccessBean;
import a66weding.com.jiehuntong.beans.WedPlanTypeBean;
import a66weding.com.jiehuntong.fragment.BaseFragmentActivity;
import a66weding.com.jiehuntong.http.OnNetResultListener;
import a66weding.com.jiehuntong.pager.ToolsPager_DayPlan_Home;
import a66weding.com.jiehuntong.pager.ToolsPager_DayPlan_addTask;
import a66weding.com.jiehuntong.pager.ToolsPager_DayPlan_editTask;

public class ToolsDayPlanActivity extends BaseFragmentActivity implements OnNetResultListener {
    private View mContentview;
    private static HashMap<String, FragmentModule> mDayPlanPages;
    private int taskModel;
    private List<WedPlanTypeBean.DataBean> mTypeList=new ArrayList<WedPlanTypeBean.DataBean>();
    private int mCurrentGroupPosition;
    private int mCurrentChildPosition;
    private boolean isEdit;
    public ToolsDayPlanActivity(){}
    @Override
    protected void onPreInitViewExecute() {
        mDayPlanPages = new HashMap<String,FragmentModule>();
        mDayPlanPages.put("任务流程主页",new FragmentModule(ToolsPager_DayPlan_Home.newInstance(this),"任务流程主页"));
        mDayPlanPages.put("添加任务流程",new FragmentModule(ToolsPager_DayPlan_addTask.newInstance(this),"添加任务流程"));
        mDayPlanPages.put("修改类型",new FragmentModule(ToolsPager_DayPlan_editTask.newInstance(this),"修改类型"));
    }

    @Override
    protected View getContentView() {
        ((GlobalApplication)getApplication()).getActivityManager().addActivity("ToolsDayPlanActivity",this);
            mContentview=initContentview();
        return mContentview;
    }

    private View initContentview() {
        return null;
    }
    @Override
    protected void onPostCreateExecute() {
    }
    @Override
    protected FragmentModule getDefaultModule() {
        return mDayPlanPages.get("任务流程主页");
    }
    @Override
    protected int getContentId() {
        return R.id.flay_baseactivity_content;
    }
    @Override
    protected HashMap<String, FragmentModule> getFragmentModule() {
        return mDayPlanPages;
    }
    @Override
    public void onSucess(SuccessBean sucessbean) {
    }
    @Override
    public void onError(ErrorBean errorBean) {
    }
    public int getTaskModel() {
        return taskModel;
    }
    public void setTaskModel(int taskModel) {
        this.taskModel = taskModel;
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Fragment mHomeFragment = getSupportFragmentManager().findFragmentByTag("任务流程主页");
        mHomeFragment.onActivityResult(requestCode,resultCode,data);
    }
        public void notifyData(String pageName){
            switch (pageName) {
                    case "任务流程主页":
                        ToolsPager_DayPlan_Home mHomeFragment = (ToolsPager_DayPlan_Home) getSupportFragmentManager().findFragmentByTag("任务流程主页");
                        mHomeFragment.notifyData(pageName);
                    break;
                     case "添加任务流程":
                         ToolsPager_DayPlan_addTask mAddFragment = (ToolsPager_DayPlan_addTask) getSupportFragmentManager().findFragmentByTag("添加任务流程");
                         mAddFragment.notifyData(pageName);

                    break;
            }

    }
    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        super.onKeyDown(keyCode, event);
        if(keyCode == KeyEvent.KEYCODE_BACK){
            if(getSupportFragmentManager().getBackStackEntryCount()==1){
                finish();
                return true;
            }
        }
        return super.onKeyUp(keyCode,event);
    }
    public Fragment getVisibleFragment(){
        FragmentManager fragmentManager = this.getSupportFragmentManager();
        List<Fragment> fragments = fragmentManager.getFragments();
        for(Fragment fragment : fragments){
            if(fragment != null && fragment.isVisible())
                return fragment;
        }
        return null;
    }
    public void setmCurrentGroupPosition(int mCurrentGroupPosition) {
        this.mCurrentGroupPosition = mCurrentGroupPosition;
    }
    public void setmCurrentChildPosition(int mCurrentChildPosition) {
        this.mCurrentChildPosition = mCurrentChildPosition;
    }
    public int getmCurrentChildPosition() {
        return mCurrentChildPosition;
    }
    public boolean isEditType() {
        return isEdit;
    }
    public void setEdit(boolean edit) {
        isEdit = edit;
    }
    public int getmCurrentGroupPosition() {
        return mCurrentGroupPosition;
    }
    public void setmTypeList(List<WedPlanTypeBean.DataBean> mTypeList) {
        this.mTypeList = mTypeList;
    }
    public List<WedPlanTypeBean.DataBean> getmTypeList() {
        return mTypeList;
    }
}
